package tech.wetech.admin3.sys.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.testng.annotations.Test;
import tech.wetech.admin3.sys.model.AooAnotherMe;
import tech.wetech.admin3.sys.model.AooAnotherSomeone;
import tech.wetech.admin3.sys.model.AooVirtualMan;
import tech.wetech.admin3.sys.repository.AooAnotherMeRepository;
import tech.wetech.admin3.sys.repository.AooAnotherSomeoneRepository;
import tech.wetech.admin3.sys.repository.AooVirtualManRepository;

@Service
public class AooCountService {

  @Autowired
  private AooAnotherMeRepository anotherMeRepository;
  @Autowired
  private AooAnotherSomeoneRepository smoeoneRepository;
  @Autowired
  private AooVirtualManRepository virtualManRepository;

  // 更新订单状态
  @Transactional
  public void updateOrder(String out_trade_no) {
    // 更新订单状态，业务逻辑
    String type = out_trade_no.substring(4, 6); // 获取type
    System.out.println("type---" + type);
    try {
      if (type.equals("me")) {
        anotherMeRepository.findByOutTradeNo(out_trade_no).setPaid(true);
      } else if (type.equals("so")) {
        smoeoneRepository.findByOutTradeNo(out_trade_no).setPaid(true);
      } else if (type.equals("vm")) {
        virtualManRepository.findByOutTradeNo(out_trade_no).setPaid(true);
      }
    }catch (Exception e){
      e.printStackTrace();
    }
  }


}

